<template>
  <!--项目执行信息  -->
  <div>
    <FormPanel
      ref="formPanel"
      :list="initForm"
      :cols="2"
      formType="show"
      :labelWidth="140"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { formatdateByDay } from '@/utils';
export default {
  mixins: [dictionary],
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      initForm: this.initFormFun(),
      formValue: {}
    };
  },
  mounted() {
    console.log(this.value); //获取到行id 、类型（新增、详情）
    //请求接口进行赋值，自己写吧
  },
  methods: {
    //日期格式化年月日
    formatDates: function(value) {
      // 这里的 value 就是需要过滤的数据
      if (value == null || value == '') {
        return '';
      }
      var date = new Date(value);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      return year + '-' + month + '-' + day;
    },
    init() {
        this.initForm.forEach(x => {
          x.initialValue = this.value.row[x.fieldName];
          if (x.fieldName == 'realStartDate') {
            x.initialValue = formatdateByDay(this.value.row.realStartDate);
          }
          if (x.fieldName == 'realEndDate') {
            x.initialValue = formatdateByDay(this.value.row.realEndDate);
          }
          if (x.fieldName == 'realLaunchReleaseTime') {
            if (this.value.row.realLaunchReleaseTime != null && this.value.row.realLaunchReleaseTime != '') {
              let releaseTime = this.value.row.realLaunchReleaseTime.split(',');
              x.initialValue = releaseTime;
            }
          }
          if (x.fieldName == 'realBuildAmount') {
            if (x.initialValue == null) {
              x.initialValue = '';
            }
          }
          if (x.fieldName == 'realBoothAmount') {
            if (x.initialValue == null) {
              x.initialValue = '';
            }
          }
          if (x.fieldName == 'planProjectAmount') {
            if (x.initialValue == null) {
              x.initialValue = '';
            }
          }
          if (x.fieldName == 'planApproveAmount') {
            if (x.initialValue == null) {
              x.initialValue = '';
            }
          }

          if (x.fieldName == 'planProjectAmount') {
            if (x.initialValue == null) {
              x.initialValue = '';
            }
          }
          if (x.fieldName == 'planApproveAmount') {
            if (x.initialValue == null) {
              x.initialValue = '';
            }
          }
          if (x.fieldName == 'realProjectAmount') {
            if (x.initialValue == null) {
              x.initialValue = '';
            }
          }
        });
      
      this.initForm.find(item => item.fieldName === 'orderCompletionRate').initialValue = this.value.row.orderCompletionRate / 100;
      this.initForm.find(item => item.fieldName === 'guestsCompletionRate').initialValue = this.value.row.guestsCompletionRate / 100;
      this.initForm.find(item => item.fieldName === 'retentionCompletionRate').initialValue = this.value.row.retentionCompletionRate / 100;
    },
    //搜索数据
    initFormFun() {
      return [
         {
          type: 'DATES',
          label: '实际开展/投放时间',
          fieldName: 'realLaunchReleaseTime',
          initialValue: null,
          placeholder: '',
          // dateType: 'date',
          valueFormat: 'yyyy-MM-dd',
          selfCols: 2,
          change: value => {
            this.initReleaseTimeSmall(value);
          } 
        },
        {
          type: 'DATE',
          label: '实际开始日期',
          fieldName: 'realStartDate',
          valueFormat: 'yyyy-MM-dd',
          initialValue: '',
          selfCols: 1,
          disabled: true
          // rules: [{ required: true, message: '请输入实际开始日期', trigger: 'blur' }]
        },
        {
          type: 'DATE',
          label: '实际结束日期',
          fieldName: 'realEndDate',
          valueFormat: 'yyyy-MM-dd',
          selfCols: 1,
          initialValue: '',
          disabled: true
          // rules: [{ required: true, message: '请输入实际结束日期', trigger: 'blur' }]
        },
         {
          type: 'INPUT_NUMBER',
          label: '实际支持天数',
          fieldName: 'realTimeDay',
          initialValue: '',
          precision: 0,
          max: 99999999,
          disabled: true 
        },
        {
          type: 'INPUT',
          label: '实际项目地点',
          fieldName: 'realProjectLocation',
          initialValue: '' 
        },
        {
          type: 'INPUT_NUMBER',
          label: '实际集客',
          fieldName: 'realGuestsNum',
          initialValue: null,
          placeholder:'数字',
          max: 99999999,
          disabled: false ,
          change: this.guestsCalcChange
        },
       
        { type: 'INPUT', label: '搭建运营批准金额', fieldName: 'realBuildAmount', placeholder: '单位（元）', initialValue: undefined,numberFormat:true
          
        },
        {
          type: 'INPUT_NUMBER',
          label: '实际留档',
          fieldName: 'realRetentionNum',
          initialValue: undefined,
          placeholder:'数字',
          max: 99999999,
          disabled: false,
          change: this.retentionCalcChange
        },
        { type: 'INPUT', label: '展位批准金额', fieldName: 'realBoothAmount',  placeholder: '单位（元）', initialValue: undefined,numberFormat:true
        },
        {
          type: 'INPUT_NUMBER',
          label: '实际订单',
          fieldName: 'realOrderNum',
          initialValue: undefined,
          placeholder:'数字',
          max: 99999999,
          disabled: false,
          change: this.orderCalcChange
        },
        { type: 'INPUT', label: '搭建运营批准金额', fieldName: 'realBuildAmount', placeholder: '单位（元）', initialValue: undefined,numberFormat:true
          
        },       
        {
          type: 'INPUT',
          label: '实际项目金额',
          fieldName: 'realProjectAmount',
          initialValue: '',
          numberFormat: true,
          rules: [{ required: true, message: '请输入实际项目金额', trigger: 'blur' }, { pattern: /[\d\.]+/g, message: '请输入数字', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '实际批准金额',
          fieldName: 'realApproveAmount',
          initialValue: '',
          disabled: true,
          placeholder: '',
          rules: [{ required: true, message: '请输入实际开始日期', trigger: 'blur' }],
          numberFormat: true
        }
      ];
    },
    formChangeHandle(val) {
      this.formValue = val;
    }
  },
  created() {
    this.init();
  }
};
</script>
